import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'
import { GetEnterpriseImageCategory } from '../Common/Conversion'

export const EnterpriseImage = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    let dataList = {
        pageSize: 50,
        hideInSearch: true,
        params: { EnterpriseUuid: oneData.uuid },
        initialValues: { EnterpriseUuid: oneData.uuid },
        get: API_LIST([oneData.uuid])['getEnterpriseEnterpriseImages'],
        added: 'posEnterpriseEnterpriseImages',
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />],
        columns: [
            {
                title: 'EnterpriseUuid',
                dataIndex: 'EnterpriseUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'tableName',
                title: '图片标题',
                valueType: 'input',
                rules: true,
                width: 350,
            },
            {
                dataIndex: 'enterpriseImageCategoryUuid',
                title: '图片类别',
                valueType: 'select',
                valueEnum: await GetEnterpriseImageCategory(),
                rules: true,
                width: 350,
            },

            {
                dataIndex: 'attachmentUuid',
                title: '文件附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },

            commonTableList.createUserName,
            commonTableList.createTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { fileUrl } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url="EnterpriseEnterpriseImages"
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }

    return dataList
}
